<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>
<body>
    <div id="app">
        <component :is="type"></component><!-- 动态组件,根据is值显示不同的组件 -->
        <button @click="handle">change</button>
    </div>
    <script>
        Vue.component('child-one',{
            template:'<div v-once>child-one</div>'//v-once缓存数据，下次用不用重新创建
        })
        Vue.component('child-two',{
            template:'<div v-once>child-two</div>'
        })
        var vm=new Vue({
            el:'#app',
            data:{
                type:'child-one'
            },
            methods:{
                handle:function(){
                    this.type=this.type==='child-one'?'child-two':'child-one'
                }
            }
        })
    </script>
</body>
</html>